package com.example.smartcity.ui.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.smartcity.R;
import com.example.smartcity.ui.Bean.TopicMessageBean;
import com.example.smartcity.ui.Tools.OkHttpUtils;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

public class AutoLifeGitBannerAdapter extends BannerAdapter<TopicMessageBean.RowsBean,AutoLifeGitBannerAdapter.BannerViewHolder> {
    private List<TopicMessageBean.RowsBean> datas;
    private int Resource;
    private Context context;
    public AutoLifeGitBannerAdapter(Context context,List<TopicMessageBean.RowsBean> datas,int Resource) {
        super(datas);
        this.datas = datas;
        this.Resource = Resource;
        this.context = context;
    }

    @Override
    public BannerViewHolder onCreateHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(Resource,viewGroup,false);
        return new BannerViewHolder(view);
    }

    @Override
    public void onBindView(BannerViewHolder bannerViewHolder, TopicMessageBean.RowsBean rowsBean, int i, int i1) {
        bannerViewHolder.bannerTitle.setText(rowsBean.getTitle());
        bannerViewHolder.bannerMessage.setText(rowsBean.getContent());
        Glide.with(context).load(OkHttpUtils.getBaseUrl(context)+rowsBean.getImgUrl()).into(bannerViewHolder.bannerImage);
    }

    static class BannerViewHolder extends RecyclerView.ViewHolder {
        private ImageView bannerImage;
        private TextView bannerTitle;
        private TextView bannerMessage;
        public BannerViewHolder(@NonNull View itemView) {
            super(itemView);
            bannerImage = itemView.findViewById(R.id.banner_image);
            bannerTitle = itemView.findViewById(R.id.banner_title);
            bannerMessage = itemView.findViewById(R.id.banner_message);
        }
    }
}
